<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>双向绑定</title>
</head>
<body>
    <div id="app">
        <input type="button" value="get请求getFun" @click="getFun">
        <input type="button" value="get请求getFun2" @click="getFun2">
        <input type="button" value="get请求getFun3" @click="getFun3">
        {{info}}
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- 官网提供的 axios 在线地址 -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <script>
        
        var vue =new Vue({
            el:"#app",
            data:{
                info:"waiting"
            },
            methods:{
                getFun:function(){
                    axios.get("http://localhost:8080/hi?name='zhangsan'").then((result)=>{
                        this.info=result.data.info
                    }).catch((err)=>{
                        console.log(err)
                    })
                },
                getFun2:function(){//axios的这一种调用方法不能访问this，推荐使用上一种
                    console.log(this.info)
                    axios.get("http://localhost:8080/joke").then(function(result){
                        // this.info=result.data.info
                        console.log(this.info)
                    },function(err){
                        console.log(err)
                    })
                },
                getFun3:function(){
                    axios.post("http://localhost:8080/hi",{name:"hi"}).then((result)=>{
                        this.info=result.data.info
                    }).catch((err)=>{
                        console.log(err)
                    })
                },
                
            }
    
        })  
    </script>
</body>
</html>